/**
 * 
 */
package com.designpattern.design.factory.easyfactory.order;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.designpattern.design.factory.easyfactory.SimplePizzaFactory;
import com.designpattern.design.factory.nofactory.Pizza;

/**
 * @author zhangyang
 *
 */
public class PizzaOrder {

	// 定义工厂变量
	SimplePizzaFactory factory;

	// 类构造器
	public PizzaOrder(SimplePizzaFactory factory) {
		// 初始化工厂
		this.factory = factory;
		//工厂创建pizza
		this.createPizza(factory);
	}

	// 写一个方法,使用简单工厂对象生成pizza
	public void createPizza(SimplePizzaFactory factory) {
		// pizza种类
		String pizzaType="";
		do {
			pizzaType = getType();
			Pizza pizza = factory.createPizza(pizzaType);
			if (pizza == null) {
				break;
			}else {
				//打印制造过程
				pizza.prepare();
				pizza.bake();
				pizza.cut();
				pizza.box();
			}

		} while (true);
	}

	// 写一个方法，可以获取客户希望订购的披萨种类
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类:");
			String str = strin.readLine();
			return str;
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}
